<template>

    <div class="container">
        <div class="jumbotron">
            这里是自定义vue初始页面3
                <form>
                    <div class="form-group">
                        <label>Name:</label>
<!--                        <input type="text" name="name" class="form-control" placeholder="Name" required="">-->
                        <input type="text" name="name" class="form-control" placeholder="Name" >
                    </div>
                    <div class="form-group">
                        <label>Password:</label>
                        <input type="password" name="password" class="form-control" placeholder="Password" >
<!--                        <input type="password" name="password" class="form-control" placeholder="Password" required="">-->
                    </div>
<!--                    <div class="form-group">-->
<!--                        <strong>Email:</strong>-->
<!--                        <input type="email" name="email" class="form-control" placeholder="Email" >-->
<!--                    </div>-->
                    <div class="form-group">
                        <button class="btn btn-success btn-submit2" v-on:click="test">Submit</button>
                    </div>
                    <div id="response"></div>   <!--用来显示错误提示的div-->
                </form>
        </div>
    </div>
</template>

<script>
    export default {
        name: "LeComponent",
        methods:{
            test:function () {
                alert('======0============');

                // e.preventDefault();
                var name = $("input[name=name]").val();
                var password = $("input[name=password]").val();
                var email = $("input[name=email]").val();

                $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});
                $.ajax({
                    type: 'POST',
                    url: '/checku',
                    // data: {name: name, password: password, email: email},
                    data: { password: password, email: email},
                    success: function (data) {
                        alert(datastatus);
                    },
                    error: data => {




                        alert(datastatus);


                        // if (data.status === 422) {
                        //     var errors = $.parseJSON(data.responseText);    //转json格式，或直接使用 data.responseJSON
                        //     $.each(errors, function (key, value) {
                        //         $('#response').addClass("alert alert-danger");
                        //         if ($.isPlainObject(value)) {
                        //             $.each(value, function (key, value) {
                        //                 console.log(key + " " + value);
                        //                 $('#response').show().append(value + "<br/>");
                        //
                        //             });
                        //         } else {
                        //             $('#response').show().append(value + "<br/>"); //this is my div with messages
                        //         }
                        //     });
                        // }
                    }
                });

                },
        }
    }


    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')    //携带csrf_token，否则会返回错误500
        }
    });
    $(".btn-submit2").click(function (e) {
        alert('======0============');
    });

    $(".btn-submit").click(function (e) {
        alert('======0============');

    });
</script>

<style scoped>

</style>



